package com.flute.framework.search;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

public class SearchFilter {
	private HashMap<String, List<String>> filters;
	public SearchFilter() {
		this.filters = new HashMap<String, List<String>>();
	}
	
	public void addFilter(String name, String value) {
		if(filters.keySet().contains(name)) {
			filters.get(name).add(value);
		} else {
			List<String> valueList = new ArrayList<String>();
			valueList.add(value);
			filters.put(name, valueList);
		}
	}
	
	public String[] getFilters() {
		return filters.keySet().toArray(new String[] {});
	}
	
	public List<String> getFilterValue(String name) {
		return filters.get(name);
	}
	
	public int size(){
		return filters.size();
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		if (filters != null) {
			Iterator<String> ite = filters.keySet().iterator();
			while (ite.hasNext()) {
				String key = ite.next();
				sb.append(key);
				for (String str : filters.get(key)) {
					sb.append(str);
				}
			}
		}
		
		return sb.toString();
	}

	
//	private HashMap<String, String> filters;
//
//	public SearchFilter() {
//		this.filters = new HashMap<String, String>();
//	}
//
//	public void addFilter(String name, String value) {
//		this.filters.put(name, value);
//	}
//
//	public String[] getFilters() {
//		return filters.keySet().toArray(new String[] {});
//	}
//
//	public String getFilterValue(String name) {
//		return filters.get(name);
//	}
//	
//	public int size(){
//		return filters.size();
//	}
}
